home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / awkstats < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  3.4 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: tr@wind.bellcore.com (tom reingold)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i013: Statistical awk scripts
  5. Message-ID: <8810221430.AA18345@wind.bellcore.com>
  6. Date: 28 Oct 88 02:44:26 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: tr@wind.bellcore.com (tom reingold)
  9. Lines: 105
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 13
  13. Submitted-by: "tom reingold" <tr@wind.bellcore.com>
  14. Archive-name: awkstats
  15.  
  16. [This was deferred for a bit in memory of the Xenix smail mods posting that
  17. had to be superseded time after time after... you get the idea.  I prefer
  18. making sure the posting is stable first....  ++bsa]
  19.  
  20. You know how it goes.  You clean your code up just to make it look
  21. pretty and you break it.  Ok, so this version works.  I hope you
  22. haven't posted yesterday's version.
  23.  
  24. Thanks!
  25.  
  26. #! /bin/sh
  27. # This is a shell archive, meaning:
  28. # 1. Remove everything above the #! /bin/sh line.
  29. # 2. Save the resulting text in a file.
  30. # 3. Execute the file with /bin/sh (not csh) to create the files:
  31. #    README
  32. #    stats1.awk
  33. #    stats2.awk
  34. # This archive created: Sat Oct 22 10:27:35 1988
  35. # By:    tom reingold (Bellcore, Morristown, Noo Joizy)
  36. export PATH; PATH=/bin:$PATH
  37. if test -f 'README'
  38. then
  39.     echo shar: will not over-write existing file "'README'"
  40. else
  41. cat << \SHAR_EOF > 'README'
  42.  
  43. Here is an awk script I wrote for the hell of it because I am home
  44. sick today.  It computes the standard boring univariate statistics.
  45. I have enclosed two versions.  "stats1.awk" requires the new new
  46. version of awk, which has user-definable functions.  (MKS awk allows
  47. this too!)  In stats1.awk, I define a function called pow, which
  48. in and of itself, is useful.  "stats2.awk" doesn't require the new
  49. awk.  It may actually be faster too since it doesn't do an interpreted
  50. function call.  But it's not as cool.
  51.  
  52. Tom Reingold
  53. PAPERNET:                      |INTERNET:       tr@bellcore.bellcore.com
  54. Bell Communications Research   |UUCP-NET:       bellcore!tr
  55. 445 South St room 2L350        |SOUNDNET:       (201) 829-4622 [work],
  56. Morristown, NJ 07960-1910      |                (201) 287-2345 [home]
  57. SHAR_EOF
  58. if test 799 -ne "`wc -c < 'README'`"
  59. then
  60.     echo shar: error transmitting "'README'" '(should have been 799 characters)'
  61. fi
  62. fi # end of overwriting check
  63. if test -f 'stats1.awk'
  64. then
  65.     echo shar: will not over-write existing file "'stats1.awk'"
  66. else
  67. cat << \SHAR_EOF > 'stats1.awk'
  68. {
  69.     a[NR] = $1
  70.     sum += a[NR]
  71.     sumsq += pow(a[NR], 2.0)
  72. }
  73. END {
  74.     mean = (sum / NR)
  75.     stddev = sqrt((sumsq / NR) - pow(mean, 2.0))
  76.     printf "sum is %1.2f, mean is %1.2f, n is %d, stddev is %1.3f\n", \
  77.         sum, mean, NR, stddev
  78. }
  79. func pow(mantissa, exponent)
  80. {
  81.     if (exponent == 0)
  82.         return(1)
  83.     if (mantissa == 0)
  84.         return(0)
  85.     return(exp(exponent * log(mantissa)))
  86. }
  87. SHAR_EOF
  88. if test 358 -ne "`wc -c < 'stats1.awk'`"
  89. then
  90.     echo shar: error transmitting "'stats1.awk'" '(should have been 358 characters)'
  91. fi
  92. fi # end of overwriting check
  93. if test -f 'stats2.awk'
  94. then
  95.     echo shar: will not over-write existing file "'stats2.awk'"
  96. else
  97. cat << \SHAR_EOF > 'stats2.awk'
  98. {
  99.     a[NR] = $1
  100.     sum += a[NR]
  101.     sumsq += (a[NR] * a[NR])
  102. }
  103. END {
  104.     mean = (sum / NR)
  105.     stddev = sqrt((sumsq / NR) - (mean * mean))
  106.     printf "sum is %1.2f, mean is %1.2f, n is %d, stddev is %1.3f\n", \
  107.         sum, mean, NR, stddev
  108. }
  109. SHAR_EOF
  110. if test 221 -ne "`wc -c < 'stats2.awk'`"
  111. then
  112.     echo shar: error transmitting "'stats2.awk'" '(should have been 221 characters)'
  113. fi
  114. fi # end of overwriting check
  115. #    End of shell archive
  116. exit 0
  117.